package leetcom;

public class EX5747 {
    long INF =  1000000000;
    public boolean splitString(String s) {

        int pre = 0;
        for (int i = 0; i <s.length()-1&&pre<INF ; i++) {
            pre = pre*10+s.charAt(i)-'0';

            if(dfs(s,i+1,pre)){
                return true;
            }
        }
        return false;
    }
    public boolean dfs(String s,int k,long pre){
        if(k==s.length()){
            return true;
        }
        long now = 0;
        for (int i = k; i <s.length()&&now<INF ; i++) {
            now = now*10+s.charAt(i)-'0';
            if(pre-1==now){
                if(dfs(s,i+1,now)){
                    return true;
                }
            }else if(pre-1<now){
                return false;
            }
        }
        return false;
    }


    public static void main(String[] args) {
        EX5747 ex5747 = new EX5747();
        ex5747.splitString("1234");
    }
}
